﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Inaction.UI.ComponentModel.Design
{
    public static class AssemblyHelper
    {
        public static List<Assembly> GetProjectAssemblies()
        {
             
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            List<Assembly> list = new List<Assembly>();
            foreach (var assembly in assemblies)
            {
                try
                {
                    var location = assembly.Location.ToUpper();
                    if (string.IsNullOrEmpty(location)) continue;
                    if (location.Contains(@"ASSEMBLY\GAC")
                        || location.Contains("VISTUALSTUDIO.")
                        || location.Contains("MICROSOFT.")
                        || location.Contains("DEVEXPRESS")
                        || location.Contains("NUGET.")
                        || location.Contains(@"\EXTENSIONS\")
                        || location.Contains("VSGRAPHICSDEBUGGERPKG")
                        || location.Contains(@"\IDE")
                        ) continue;
                }
                catch (Exception) { continue; }
                if (list.Any(p => p.GetName().Name.Equals(assembly.GetName().Name))) continue;
                list.Add(assembly);
            }
            return list;
        }
    }
}
